package com.fms.fmsapi.entity;

import com.fms.fmsapi.common.ResponseEnum;
import lombok.Data;

@Data //lombok中的注解
public class R {//这里名为R，主要原因是这个调用次数很多，便于编写
    private Integer code;
    private String msg;
    private Object data;

    public R(Integer code, String msg, Object data) {//普通构造函数
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(ResponseEnum responseEnum, Object data){//含枚举类和数据构造函数
        this.code = responseEnum.getCode();
        this.msg = responseEnum.getMsg();
        this.data = data;
    }

    public R(ResponseEnum responseEnum){//只含枚举类
        this.code = responseEnum.getCode();
        this.msg = responseEnum.getMsg();
    }

    public static R success(Object data){//将原来的处理结果类的工具类的方法整合到了结果类里面
        //同样是便于代码编写
        return new R(ResponseEnum.SUCCESS, data);
    }

    public static R fail(ResponseEnum responseEnum){//同上，这个是用于枚举类中存在映射关系的
        return new R(responseEnum);
    }

    public static R fail(Integer code, String msg){//与上相反，用于你不想写映射关系的
        return new R(code, msg, null);
    }
}
